﻿var silverlightPluginId = 'Silverlight1';
var aid;
var facebookCookie;

function facebook_init(appid) {
    FB.init({ 'appId': appid, 'status': true, 'cookie': true, 'xfbml': true });
    aid = appid;
}

function isUserConnected(appid) {
    FB.Event.subscribe('auth.login', function(response) {
        // do something with response
        facebook_onlogin(response.session);
    });
    FB.Event.subscribe('auth.logout', function(response) {
        // do something with response  
        facebook_onlogout();
    });
    FB.getLoginStatus(function(response) {
        if (response.session) {
            // logged in and connected user, someone you know
            facebook_onlogin(response.session);
        }
    });
}

function facebook_login(appid, permissions) {
    FB.login(function(response) {
        if (response.session) {
            facebook_onlogin(response.session)

        } else {
        }
    }, { perms: permissions });
}

function facebook_logout() {
    FB.Connect.logout(facebook_onlogout);
    facebook_logout();
}


function facebook_onlogout() {
    var plugin = document.getElementById(silverlightPluginId);
    plugin.Content.FacebookLoginControl.LoggedOut();
}
function facebook_onlogin(session) {
    var plugin = document.getElementById(silverlightPluginId);
    plugin.Content.FacebookLoginControl.LoggedIn(session.access_token, session.uid);
}

